﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

public partial class user_user_group_func : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
        }
        else //第一次显示本页
        {
            string grpcode = this.Request["grpcode"].ToString();
            TUserGrantGroup oGroup = new TUserGrantGroup(grpcode);
            oGroup.Select();
            group_name.Text = oGroup.GrpName;
            group_code.Text = oGroup.GrpCode;
            //----
            DisplayRS1();
            DisplayRS2();
        }
    }
    private void DisplayRS1()
    {
        lbLeft.Items.Clear();
        string sSql = "select funccode,funcname from t_user_func where status=0 and funccode not in (select funccode from t_user_grantfunc where grpcode='" + group_code.Text + "') order by sortnum";
        TSqlDBReader myReader = new TSqlDBReader(sSql);
        while (myReader.FDataReader.Read())
        {
            ListItem Item;
            Item = new ListItem(myReader.FDataReader.GetValue(1).ToString(), myReader.FDataReader.GetValue(0).ToString());
            /*
            if (myReader.FDataReader.GetValue(2).ToString() == "0")
            {
                Item = new ListItem(myReader.FDataReader.GetValue(1).ToString(), myReader.FDataReader.GetValue(0).ToString());
            }
            else
            {
                Item = new ListItem(HttpUtility.HtmlDecode("&nbsp;&nbsp;") + myReader.FDataReader.GetValue(1).ToString(), myReader.FDataReader.GetValue(0).ToString());
            }
            */
            lbLeft.Items.Add(Item);
        }
        myReader.Free();
    }

    private void DisplayRS2()
    {
        lbRight.Items.Clear();
        string sSql = "select funccode,funcname from t_user_func where funccode in (select funccode from t_user_grantfunc where grpcode='" + group_code.Text + "')";
        TSqlDBReader myReader = new TSqlDBReader(sSql);
        while (myReader.FDataReader.Read())
        {
            ListItem Item;
            Item = new ListItem(myReader.FDataReader.GetValue(1).ToString(), myReader.FDataReader.GetValue(0).ToString());
            /*
            if (myReader.FDataReader.GetValue(2).ToString() == "0")
            {
                Item = new ListItem(myReader.FDataReader.GetValue(1).ToString(), myReader.FDataReader.GetValue(0).ToString());
            }
            else
            {
                Item = new ListItem(HttpUtility.HtmlDecode("&nbsp;&nbsp;") + myReader.FDataReader.GetValue(1).ToString(), myReader.FDataReader.GetValue(0).ToString());
            }
             */ 
            lbRight.Items.Add(Item);
        }
        myReader.Free();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        TUserGrantFunc oFunc = new TUserGrantFunc();
        oFunc.GrpCode = group_code.Text;
        oFunc.FuncCode=lbLeft.SelectedValue;
        oFunc.Insert();
        //----
        DisplayRS1();
        DisplayRS2();
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        TUserGrantFunc.DeleteByItem(group_code.Text,lbRight.SelectedValue);
        //----
        DisplayRS1();
        DisplayRS2();
    }
}
